package testsuits;
import java.util.ArrayList;

import org.junit.Test;

import entities.Patient;

import utilities.RESTClient;
import junit.framework.TestCase;

public class RESTClientTest extends TestCase 
{
	private RESTClient client;
	private ArrayList<Patient> patients;
	private static final String LOGIN_ID = "sa";
	private static final String LOGIN_PWD = "RIca68BFjtMU";
	private static final String LOGIN_URL = "http://88.116.105.228:30102";

	protected void setUp() throws Exception 
	{
		client = RESTClient.getInstance();
		patients = new ArrayList<Patient>();
	}

	protected void tearDown() throws Exception 
	{
		client = null;
		patients.clear();
	}
	
	@Test
	public void connect_shouldReturnTrueWhenSuccessful()
	{
		assertTrue(client.connect(LOGIN_ID, LOGIN_PWD, LOGIN_URL));
	}
	
	@Test
	public void connect_shouldReturnFalseWhenAuthFails()
	{
		assertFalse(client.connect(LOGIN_ID, "test123", LOGIN_URL));
	}
	
	@Test
	public void connect_shouldReturnFalseWhenServerUnavailable()
	{
		assertFalse(client.connect(LOGIN_ID, LOGIN_PWD, "8.8.8.8:30102"));
	}
	
	@Test
	public void getPatients_shouldReturnListOfPatients()
	{
		client.connect(LOGIN_ID, LOGIN_PWD, LOGIN_URL);
		patients = client.getPatients();
		assertEquals("00000000-0000-0000-0000-000000000001", patients.get(0).getDocumentUri().toString());
	}
	
	@Test
	public void getPatients_shouldReturnNullIfNotAuth()
	{
		assertEquals(null, client.getPatients());
	}
}
